/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var country;
var countryrequest;
function lookUpCountry()
{
    alert('lookUpCountry');
    country = document.getElementById("txtcountry");

    var curl = "RegistrationAction?action=lookup&country=" + (country.value);

    if (window.XMLHttpRequest) {
        alert('window.XMLHttpRequest');
        if (navigator.userAgent.indexOf('MSIE') !== -1) {
            isIE = true;
            countryrequest = new XMLHttpRequest();
        }
        else if (navigator.userAgent.indexOf('Chrome') !== -1) {
            isChrome = true;
            //  alert('chrome');
            countryrequest = new XMLHttpRequest();
        }
        else if (navigator.userAgent.indexOf('Firefox') !== -1) {
            isFirefox = true;
            countryrequest = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            isIE = true;
            countryrequest = new ActiveXObject("Microsoft.XMLHTTP");  //old versions of IE (IE5 and IE6)
        }
    }
    //   alert('Before request.open' + countryrequest);
    countryrequest.open("GET", curl, true);
    //  alert('send request to Servlet ,lookup country');
    countryrequest.onreadystatechange = callbackCountry;
    countryrequest.send();

}


function callbackCountry()
{
    if (countryrequest.readyState === 4 && countryrequest.status === 200) {
        alert('success status' + countryrequest.responseXML);
        var countries = countryrequest.responseXML.getElementsByTagName("countries")[0];
        if (countries.childNodes.length > 0) {
            for (i = 0; i < countries.childNodes.length; i++) {
                var country = countries.childNodes[i];
                var countryname = country.getElementsByTagName("countryName")[0];
                alert('retrieve country name ' + countryname.childNodes[0].nodeValue);
            }
        }
    }
}